/**
 * 	this is the Initiator Panel
 */

package gui;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class InitiatorPanel extends JPanel {
	
	String pid;
	AcademicFrame frame;
	MainWindow mainWindow;
	InitiatorPanel initiatorPanel;
	public InitiatorPanel(AcademicFrame frame,MainWindow mainWindow,String pid) {
		
		super();
		this.pid=pid;
		this.frame=frame;
		this.mainWindow=mainWindow;
		this.initiatorPanel=this;
		frame.setSize(500, 400);
		initialize();
		
	}
	
	private void initialize() {
		setLayout(null);
		
		JLabel lblInitiator = new JLabel("Initiator");
		lblInitiator.setForeground(Color.BLUE);
		lblInitiator.setFont(new Font("Tahoma", Font.BOLD, 26));
		lblInitiator.setBounds(167, 27, 127, 22);
		add(lblInitiator);
		
		JButton btnRequestChange = new JButton("Request Change");
		btnRequestChange.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				frame.setContentPane(new RequestChangePanel(frame, initiatorPanel,pid));
				frame.setSize(705, 670);
				
				ArrayList<Object> info= new ArrayList<Object>();
				info.add("getInfo");
				info.add(pid);			
				AcademicFrame.myclient.sendMessageToServer(info); // get user information
				
				ArrayList<Object> listofsystems = new ArrayList<Object>();
				listofsystems.add("getListOfSystems");
				AcademicFrame.myclient.sendMessageToServer(listofsystems); // get list of systems
				
			}
		});
		btnRequestChange.setBounds(63, 134, 127, 23);
		add(btnRequestChange);
		
		JButton btnTrackChange = new JButton("Track Change");
		btnTrackChange.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				frame.setContentPane(new TrackChangePanel (frame, initiatorPanel,pid));
				frame.setSize(630, 490);
				
				ArrayList<Object> requestHistory= new ArrayList<Object>();
				requestHistory.add("getRequestHistory");
				requestHistory.add(pid);			
				AcademicFrame.myclient.sendMessageToServer(requestHistory); // get user request history
			}
		});
		btnTrackChange.setBounds(276, 134, 121, 23);
		add(btnTrackChange);
		
		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frame.setSize(500, 500);
				frame.setContentPane(mainWindow);
			}
		});
		btnBack.setBounds(187, 241, 89, 23);
		add(btnBack);
	}
}
